<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData"/>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="8">
        <piechart></piechart>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <chatroom></chatroom>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <commit></commit>
      </el-col>
    </el-row>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <common-chart :chart-data="lineChartData"/>
    </el-row>

  </div>
</template>

<script>
import PanelGroup from './PanelGroup.vue'
import Chatroom from "@/views/dashboard/chatroom/index.vue";
import Commit from "@/views/dashboard/commit/index.vue";
import Piechart from "@/views/dashboard/piechart/index.vue";
import CommonChart from "@/views/echarts/CommonChart.vue";

const lineChartData = {
  newVisitis: {
    one: [100, 120, 161, 134, 105, 160, 165],
    two: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    one: [200, 192, 120, 144, 160, 130, 140],
    two: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    one: [80, 100, 121, 104, 105, 90, 100],
    two: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    one: [130, 140, 141, 142, 145, 150, 160],
    two: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'Index',
  components: {
    CommonChart,
    Piechart,
    Commit,
    Chatroom,
    PanelGroup,
  },
  data() {
    return {
      lineChartData: null
    }
  },
  created() {
    this.handleSetLineChartData('newVisitis')
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = {
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['Email', 'Union Ads']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: 'Email',
            type: 'line',
            stack: 'Total',
            data: lineChartData[type].one
          },
          {
            name: 'Union Ads',
            type: 'line',
            stack: 'Total',
          },
          {
            name: 'Union Ads',
            type: 'line',
            stack: 'Total',
            data: lineChartData[type].two
          }
        ]
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 20px;
  background-color: rgb(240, 242, 245);

  .el-col {
    margin-bottom: 32px;
  }
}
</style>
